﻿using JanusLibAing.AutoSave;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace JanusTestProject
{
    /// <summary>
    ///This is a test class for AutoSaverTest and is intended
    ///to contain all AutoSaverTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AutoSaverTest
    {
        private const string RootFolder = "c:\\";
        private const string FileName = "test";
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AutoSaver Constructor
        ///</summary>
        [TestMethod()]
        public void AutoSaverConstructorTest()
        {
            //AutoSaver target = new AutoSaver();
        }

        /// <summary>
        ///A test for AddItem
        ///</summary>
        [TestMethod()]
        public void AddItemTest()
        {
            //AutoSaver target = new AutoSaver(); //  Initialize to an appropriate value
            //IDataItem item = null; //  Initialize to an appropriate value
            //target.AddItem(item);
        }

        /// <summary>
        ///A test for Load
        ///</summary>
        [TestMethod()]
        public void LoadTest()
        {
            AutoSaver target = new AutoSaver(new TestFactory(), FileName); 
            target.RootFolder = RootFolder;

            target.Load(AutoSaverTest.FileName);
            Assert.AreEqual(4, target.ItemCount);

            IDataItem dataItem1 = target[0];
            Assert.AreEqual(typeof(TestString),dataItem1.GetType());
            Assert.AreEqual(TestString.Key, dataItem1.Name);
            Assert.AreEqual("Пример текста",dataItem1.Value);

            IDataItem dataItem2 = target[1];
            Assert.AreEqual(typeof(TestInteger), dataItem2.GetType());
            Assert.AreEqual(TestInteger.Key, dataItem2.Name);
            Assert.AreEqual(99, dataItem2.Value);

            IDataItem dataItem3 = target[2];
            Assert.AreEqual(typeof(TestEnum), dataItem3.GetType());
            Assert.AreEqual(TestEnum.Key, dataItem3.Name);
            Assert.AreEqual(ETest.Test1, dataItem3.Value);

            IDataItem dataItem4 = target[3];
            Assert.AreEqual(typeof(TestEnumValue), dataItem4.GetType());
            Assert.AreEqual(TestEnumValue.Key, dataItem4.Name);

            Assert.AreEqual(ETest.Test1, dataItem4.Value);
        }

        /// <summary>
        ///A test for Write
        ///</summary>
        [TestMethod()]
        public void WriteTest()
        {
            AutoSaver target = new AutoSaver(new TestFactory(), FileName);
            target.RootFolder = RootFolder;

            TestString testString = new TestString("Пример текста");
            target.AddItem(testString);

            TestInteger testIntegetr = new TestInteger(99);
            target.AddItem(testIntegetr);

            TestEnum testEnum = new TestEnum(ETest.Test1);
            target.AddItem(testEnum);

            TestEnumValue testEnumValue = new TestEnumValue(ETest.Test1);
            target.AddItem(testEnumValue);

            target.Write(AutoSaverTest.FileName);
        }

        /// <summary>
        ///A test for ItemCount
        ///</summary>
        [TestMethod()]
        public void ItemCountTest()
        {
            AutoSaver target = new AutoSaver(new TestFactory(), FileName);
            int actual;
            actual = target.ItemCount;
        }

        /// <summary>
        ///A test for RootFolder
        ///</summary>
        [TestMethod()]
        public void RootSaveFolderTest()
        {
            AutoSaver target = new AutoSaver(new TestFactory(), FileName);
            string expected = string.Empty; 
            string actual;
            target.RootFolder = expected;
            actual = target.RootFolder;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for SaveInterval
        ///</summary>
        [TestMethod()]
        public void SaveIntervalTest()
        {
            AutoSaver target = new AutoSaver(new TestFactory(), FileName); 
            int expected = 0; 
            int actual;
            target.SaveInterval = expected;
            actual = target.SaveInterval;
            Assert.AreEqual(expected, actual);
        }
    }
}
